package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.BusinessService;
import com.tarena.lbs.pojo.basic.param.BusinessParam;
import com.tarena.lbs.pojo.basic.query.BusinessQuery;
import com.tarena.lbs.pojo.basic.vo.BusinessCategoryVO;
import com.tarena.lbs.pojo.basic.vo.BusinessVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    @GetMapping("/admin/basic/business/category/list")
    public Result<List<BusinessCategoryVO>> getCategory(){
        List<BusinessCategoryVO> vos =  businessService.getCategory();
        return new Result<>(vos);
    }

    /**
     * 查询商家列表，分页查询
     * @param query
     * @return
     */
    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> getBusinessInfo(BusinessQuery query) throws BusinessException {
        PageResult<BusinessVO> pageResult = businessService.getBusinessInfo(query);
        return new Result<>(pageResult);
    }

    @PostMapping("/admin/basic/business/info/save")
    public Result<Void> save(@RequestBody BusinessParam businessParam) throws BusinessException {
        businessService.save(businessParam);
        return Result.success();
    }
}
